const config = require('./config')
module.exports=function(path,data,method){
  return new Promise((resolve,reject)=>{
    wx.request({
      url: config.baseUrl+path,
      method:method,
      data:data,
      success:res=>{
        console.log(res)
        if (res.statusCode !== 200) {
          fail('服务器异常',reject)
          return
        }
        if (res.data.code === 0 ) {
          fail(res.data.meg,reject)
          return
        }
        resolve(res.data)
      },
      fail:function(){
        fail('加载数据失败',reject)
      }
    })
  })
}
function fail(title,callback) {
  wx.showModal({
    title: title,
    content: '重试',
    success:res=>{
      if (res.confirm) {
        callback()
      }
    }
  })
}